package com.tx.admin.security.service.impl;

import java.security.Key;

import org.apache.shiro.codec.Hex;
import org.apache.shiro.crypto.AesCipherService;
import org.springframework.stereotype.Component;

import com.tx.admin.security.service.AesService;

@Component
 class AesServiceImpl implements AesService{
	

	private AesCipherService aesCipherService ;
	
	private Key key;
	
	public AesServiceImpl() {
		super();

		this.aesCipherService = new AesCipherService();  
		this.key =aesCipherService.generateNewKey();
	}

	@Override
	public String encrypt(String text) {
		// TODO Auto-generated method stub
		return aesCipherService.encrypt(text.getBytes(), key.getEncoded()).toHex();  
	}

	@Override
	public String decrypt(String encrptText) {
		// TODO Auto-generated method stub
		 return new String(aesCipherService.decrypt(Hex.decode(encrptText), key.getEncoded()).getBytes());    
	}

	public AesCipherService getAesCipherService() {
		return aesCipherService;
	}

	public void setAesCipherService(AesCipherService aesCipherService) {
		this.aesCipherService = aesCipherService;
	}

	public Key getKey() {
		return key;
	}

	public void setKey(Key key) {
		this.key = key;
	}

	public static void main(String[] args) {
		AesServiceImpl aesService = new AesServiceImpl();
		System.out.println(aesService.encrypt("dass"));
	}
}
